package com.labirynt;

import com.labirynt.mat.Rectangle;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
public abstract class  GameObject {
	
	protected int xPos;
	protected int yPos;
	public int width;
	public int height;
	protected int iMaxStep;
	protected String obiektName; //Nazwa Obiektu
	protected Rect sRectangle;
	protected int spriteHeight;
	protected int spriteWidth;
//	private Rect bounds;
	protected boolean dispose;
	 protected int fps;
	 protected int numFrames;
	 protected int currentFrame;
	 protected long frameTimer;
	 protected boolean loop;
	 protected Bitmap animation; 
	 private MechanicGame mechanic;
	 public GameObject( String name, int x, int y, int width, int height) 
	 {    
		 this.xPos =x;
		 this.yPos = y;
	     this.sRectangle = new Rect(x-width/2, y-height/2, width, height);
	     
    
	     this.setObiektName(name);
	    
	     
	        this.spriteHeight = height;
			this.spriteWidth = width;
			setRect(x, y);
			 dispose = false;
	     //this.innitMechanicGme(50, 10);
	 }
	private void setRect(int x, int y) {
		this.sRectangle.top = 0;
		this.sRectangle.bottom = y+spriteHeight;
		this.sRectangle.left = 0;
		this.sRectangle.right =x+ spriteWidth;
	}
	 public void Initialize(int iMaxStep, int fps,int frameCount, boolean loop) {
			if(fps!=0)
				this.fps = 1000 / fps;
			else 
				this.fps =0;
			this.numFrames = frameCount;
			this.currentFrame=0;
			this.loop = loop;
			this.iMaxStep =iMaxStep;
		}
	 
		
		public void innitMechanicGme(int iHitPoints,int iSkill  ){
			setMechanic(new MechanicGame(iHitPoints,iSkill));
         }
		
		protected MechanicGame getMechanicGame()
		{
			
			return this.getMechanic();
		}
		
	     public int getXPos() {
			return xPos;
		}

		public int getYPos() {
			return yPos;
		}
		

		public void setXPos(int value) {
			xPos = value - (spriteWidth / 2);
		}

		public void setYPos(int value) {
			yPos = value - (spriteHeight / 2);
		}
		
	    
        //Kontrola kolizji
	  protected boolean intersectRect(GameObject  go2)
	    {
		  boolean bKolizja =false;
		  
		  if(xPos < go2.xPos && go2.xPos-xPos<50 )
			  bKolizja =true;
				else 	if(xPos > go2.xPos && xPos -go2.xPos<50)
					  bKolizja =true;
				if(bKolizja && yPos<go2.yPos && go2.yPos- yPos<50)
				return true;
				else if(bKolizja && yPos>go2.yPos &&  yPos-go2.yPos<50)
			   return true;
				
				return false;
				
	    	/*
		  return  !( go2.xPos >this.xPos+this.spriteWidth
	    		||  go2.xPos +go2.spriteWidth < this.xPos
	    		|| go2.yPos+ go2.spriteHeight > this.yPos
	    		|| go2.yPos < this.yPos+ this.spriteHeight
	    		);
	    		*/
	    }
	    
	  public abstract boolean isCollision(int x,int y);

	  
	  public abstract boolean isCollisionWith(GameObject other); 
	
	public abstract void SetPos(int x,int y);
	public abstract void draw(Canvas canvas);
	
	 public abstract void Update(long now);
	public String getObiektName() {
		return obiektName;
	}
	public void setObiektName(String obiektName) {
		this.obiektName = obiektName;
	}
	public MechanicGame getMechanic() {
		return mechanic;
	}
	public void setMechanic(MechanicGame mechanic) {
		this.mechanic = mechanic;
	}
	
//	 public abstract void LoadAnimation(String animBmp, Context ctx);

	
}
